package com.qf.day06.Homework;

import java.text.DecimalFormat;
import java.util.Random;

/**
 * 作业：
 * 创建一个父类：Hero ，属性有 名字，力量，智力，敏捷， 方法有 徒手攻击（攻击力=力量的上下百分之20）
 * 创建一个子类：战士， 独有的属性，怒气值。独有的方法，英勇打击，（攻击力=力量的上下百分之20*2，消耗20怒气）。
 */
public class Hero {
    private String name;
    int  power;//力量
    private int intelligence;//智力
    private int agile;//敏捷
    public  Hero(){

    }
    public  Hero(String name, int power, int intelligence, int agile) {
        this.name = name;
        this.power = power;
        this.intelligence = intelligence;
        this.agile = agile;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPower() {
        return power;
    }

    public void setPower(int power) {
        this.power = power;
    }

    public int getIntelligence() {
        return intelligence;
    }

    public void setIntelligence(int intelligence) {
        this.intelligence = intelligence;
    }

    public int getAgile() {
        return agile;
    }

    public void setAgile(int agile) {
        this.agile = agile;
    }

    public void unarmedAttack(){
        Random r = new Random();
        double min = power *0.8;
        double max = power+ power*0.2;
        double randomFloat = generateRandomFloat(min, max);
        System.out.println(name+"的攻击力是"+randomFloat);

    }
    public static double generateRandomFloat(double min, double max) {
        if (min >= max) {
            throw new IllegalArgumentException("Min value must be less than max value");
        }

        Random random = new Random();
        double range = max - min;
        double randomValue = min + (random.nextDouble() * range);
        return Math.round(randomValue * 100.0) / 100.0; // 保留两位小数
    }
    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", power=" + power +
                ", intelligence=" + intelligence +
                ", agile=" + agile +
                '}';
    }
}
